package com.unohacha.qqj.fzdr.personal.view.activity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.common.bean.HttpResult;
import com.unohacha.qqj.fzdr.common.http.RetrofitManager;
import com.unohacha.qqj.fzdr.util.Prefer;
import com.unohacha.qqj.mylibrary.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Callback;
import retrofit2.Response;

public class EditInfoActivity extends BaseActivity {

    private final static String TAG = "EditInfoActivity";

    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;

    // 输入信息
    @BindView(R.id.et_content)
    EditText etContent;

    @OnClick(R.id.common_back)
    public void setCommonBack() {
        finish();
    }

    // 确定修改
    @OnClick(R.id.common_right_text)
    void onEditInfoClick() {
        retrofit2.Call<HttpResult<String>> call = RetrofitManager.getInstance().setPersonalInfo(
                Prefer.getInstance().getToken(),
                getIntent().getStringExtra("typeid"),
                etContent.getText().toString().trim());
        call.enqueue(new Callback<HttpResult<String>>() {
            @Override
            public void onResponse(retrofit2.Call<HttpResult<String>> call, Response<HttpResult<String>> response) {
                if (response.body() != null) {
                    String data = response.body().getData();
                    Log.d(TAG, "onResponse: ");
                    editSuccess();
                }
            }

            @Override
            public void onFailure(retrofit2.Call<HttpResult<String>> call, Throwable t) {

            }
        });
    }

    private void editSuccess() {
        Toast.makeText(getApplicationContext(), "完成修改", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_edit_infomation;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    protected void initView() {
//        super.initView();
        // 1-企业名称；2-企业地址；3-公司电话；4-公司简介；5-用户名
        String title = "";
        String hint = "";
        switch (getIntent().getStringExtra("typeid")) {
            case "1":
                title = "企业名称";
                break;
            case "2":
                title = "企业地址";
                break;
            case "3":
                title = "公司电话";
                break;
            case "4":
                title = "公司简介";
                break;
            case "5":
                title = "用户名";
                break;
        }
        commonTitle.setText(title);
        commonRightImage.setVisibility(View.GONE);
        commonRightText.setText("完成");
        commonRightText.setTextColor(Color.GREEN);
        etContent.setHint("请输入" + title);
        commonRightText.setVisibility(View.VISIBLE);
    }
}
